var app = new Vue({
    el: '#app',
    data() {
        return {
            navList: null,
            curIndex: 0,
            twoList: null,
            curTwo: 0,
            goodslist: null,
            categoryHistory: JSON.parse(localStorage.getItem('categoryHistory')) || null
        }
    },
    created() {
        this.getClassList()
    },
    methods: {
        // 返回
        goback() {
            window.location.href = '../'
        },
        getAddress() {
            window.location.href = '/my/my_shouhuo.html'
        },
        getClassList() {
            Axios.post('/goods/category/showCategory.do', {
                parentId: 893
            }).then(res => {
                if (res.respCode === 'S') {
                    let list = res.data
                    this.navList = list
                    if(this.categoryHistory){
                        this.changeIndex(this.categoryHistory.curIndex)
                    }else{
                        this.getClassPage()
                    }
                }
            }).catch(err => {
                console.error(err)
            })
        },
        changeIndex(index) {
            if (this.curIndex !== index) {
                this.curIndex = index
                this.curTwo = 0
                this.getClassPage()
            } else {
                this.getClassPage()
            }
        },
        getClassPage() {
            Axios.post('/goods/category/showCategory.do', {
                parentId: this.navList[this.curIndex].categoryId
            }).then(res => {
                let two = res.data
                this.twoList = two
                if(this.categoryHistory){
                    this.changeTwo(this.categoryHistory.curTwo)
                } else {
                    this.getGoodsPage()
                }
            }).catch(err => {
                console.error(err)
            })
        },
        changeTwo(index) {
            if (this.curTwo !== index) {
                this.curTwo = index
                localStorage.setItem('categoryHistory',JSON.stringify({
                    curIndex:this.curIndex,
                    curTwo:this.curTwo,
                }))
                this.getGoodsPage()
            } else {
                this.getGoodsPage()
            }
        },
        getGoodsPage() {
            Axios.post('/goods/category/showCategory.do', {
                parentId: this.twoList[this.curTwo].categoryId
            }).then(res => {
                let goods = res.data
                this.goodslist = goods
            }).catch(err => {
                console.error(err)
            })
        }
    }
})
